/**
 * Author: runlin tang
 * Creation Time: 2016/9/2.
 * Description:...
 */
define(['jquery','artTemplate','../m/macPostM', '../../../common/js/lib/text!../../../tpl/footer.tpl'],
    function ($,artTemplate,macPostM,footerT) {
        function macV(datas) {
            var checkVal = (datas.data.enable != null ) ? datas.data.enable : 0;
            var ischeck = (datas.data.enable != null && datas.data.enable !=0) ? 'check-span-current' : '';
            var host_mac = (datas.data.host_mac != null ) ? datas.data.host_mac : '';
            var clone_mac = (datas.data.clone_mac != null ) ? datas.data.clone_mac : '';
            var html = '';
            html+='<div class="header"><a href="/h5-wizard/index.html#advanced-setting" class="back-a"></a><p>MAC地址克隆</p><a class="header-right">保存</a></div>';
            html+='<div class="content">';
            html+='<div class="success-txt m-t-6" style="height: 2.4rem;"><i>MAC地址克隆</i><span class="check-span '+ischeck+'"><input type="hidden" value="'+checkVal+'" class="wifi_enable"></span></div>';
            html+='<div class="success-txt m-t-6 relative-bottom right-input"><i>MAC地址</i><input type="text" class="mac" value="'+datas.data.clone_mac+'"><p>本机MAC：<strong class="host_mac">'+host_mac+'</strong></p></div>';
            html+='</div>';

            var footer = artTemplate.compile(footerT);
            html += footer({type:4});
            $(".webApp-content").html(html);

            $(".m-t-6").on('click','.check-span',function(){
                var input_obj = $(this).find('input');
                if($(this).hasClass('check-span-current')){
                    $(this).removeClass('check-span-current');
                    input_obj.val('0');
                }else{
                    $(this).addClass('check-span-current');
                    input_obj.val('1');
                }
            });
            $(".header-right").on('click',function(){
                var wifi_enable = parseInt($(".wifi_enable").val());
                var host_macs = $(".host_mac").html();
                var macs = $(".mac").val();

                var data = JSON.stringify({
                    "enable":wifi_enable,
                    "mac": macs,
                    "host_mac": host_macs,
                })
                macPostM(data);
            });

        }

        return macV;
    });
